<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { findTable, putTable } from "@/api/apiJson";

defineOptions({
  name: "edit"
});
const props = defineProps({
  params: {
    type: Object
  },
  from_config: {
    type: Object,
    required: true,
    default: () => {
      return {
        columns: []
      };
    }
  },
  businessCode: {
    type: String,
    required: true
  }
});
/**
 * 本行数据
 */
const values = ref({});
const id = props.params.row[`${props.businessCode}`].id;
const visible = ref(true);
const emit = defineEmits(["search"]);

// ============================业务操作========================================

async function getData() {
  values.value = await findTable(props.businessCode, { id });
}

async function handleConfirm() {
  await putTable(
    props.businessCode,
    values.value[`${props.businessCode}`]
  ).then(() => {
    emit("search");
    visible.value = false;
  });
}

onMounted(() => {
  getData();
});
</script>

<template>
  <PlusDialogForm
    v-model:visible="visible"
    v-model="values"
    :title="props.params.text"
    :form="{ columns: props.from_config.columns }"
    @confirm="handleConfirm"
  />
</template>
